import time

from selenium.webdriver.common.by import By

from Pages import BasePage


class visaPage(BasePage.Action):

    def __init__(self):
        self.visaIcon_xpath = (By.XPATH, "//li[@class = 'nav-visa']")
        #目的国家
        self.destCountryInput_xpath = (By.XPATH, "//div[@class = 'label' and text() = '目的国家']/following-sibling::div[@class = 'input']")
        #大洋洲tab，多个，visa需取最后一个
        self.OceaniaTab_xpath = (By.XPATH, "//div[@class = 'city-content']/div/ul/li[contains(text(),'大洋洲')]")
        #澳大利亚
        self.Australia_xpath = (By.XPATH, "//li[@title = '澳大利亚']")
        #常住地
        self.residence_xpath = (By.XPATH, "//div[@class='label' and text()='常住地']/following-sibling::div[@class='input']")
        #常住地-江苏
        self.jiangsu_xpath = (By.XPATH, "//div[@class = 'keyword-content']/dl/dd/span[@class='type-txt' and text()='江苏']")
        #出发日期，多个，visa需取最后一个
        self.departDate_xpath = (By.XPATH, "//div[@class='label' and text()='出发日期']/following-sibling::div[@class='input']")
        #出发日期 = 当前日期+28天
        self.dateVisaGoDay = time.strftime('%Y-%m-%d', time.localtime(time.time()+2419200))
        self.dateVisaGoDay_xpath = (By.XPATH,"//span[contains(@class,'day-cell') and not(contains(@class,'datepicker-item-disabled')) and @data-date='%s']" % self.dateVisaGoDay)
        #首页搜索按钮，多个，visa需取最后一个
        #可复用机票页面定义的搜索元素   self.searchButton_xpath = (By.XPATH, "//div[@class = 'train-search']/div/button[text() = '搜索']")

        #列表页-办理按钮列表
        self.listToBook_xpath = (By.XPATH,"//div[@class = 'btns']/div[@class = 'btn' and text() = '办理']")
        #详情页-立即办理按钮
        self.detailToBook_xpath = (By.XPATH, "//div[@class = 'operate']/button[@class = 'book-btn']")

        #下单页
        #出行人list
        self.passengers_xpath = (By.XPATH, "//div[@class = 'passenger-block']/div/ul/li")
        #客户类型
        self.passengerType_xpath = (By.XPATH, "//div/input[@placeholder='请选择客户类型']")
        #在职人员
        self.employed_xpath = (By.XPATH, "//div/ul/li/span[text()='在职人员']")
        #确认提交按钮
        self.submit_xpath = (By.XPATH, "//div[@class = 'submit']")
        #提交成功后关闭弹框的确认按钮
        self.sure_xpath = (By.XPATH, "//div[@class='el-message-box__btns']/button")

    def click_visaIcon(self):
        self.smart_click(*self.visaIcon_xpath)

    def chooseCounrty(self):
        self.find_element(*self.destCountryInput_xpath).click()
        self.find_elements(*self.OceaniaTab_xpath)[-1].click()
        time.sleep(2)
        #选择目的国家：澳大利亚
        self.smart_click(*self.Australia_xpath)

    def chooseResidencePalce(self):
        self.smart_click(*self.residence_xpath)
        time.sleep(1)
        #选择常住地：江苏
        self.smart_click(*self.jiangsu_xpath)

    def chooseDepartDate(self):
        self.find_elements(*self.departDate_xpath)[-1].click()
        time.sleep(1)
        self.find_elements(*self.dateVisaGoDay_xpath)[-1].click()

    def toBookVisa_list(self):
        self.find_elements(*self.listToBook_xpath)[0].click()
        time.sleep(3)

    def toBookVisa_detail(self):
        self.smart_click(*self.detailToBook_xpath)
        time.sleep(2)

    def choosePassengerType(self):
        time.sleep(1)
        self.find_element(*self.passengerType_xpath).click()
        time.sleep(2)
        self.find_element(*self.employed_xpath).click()
        time.sleep(2)

    def selectPassengers(self):
        #选中前3位常用出行人
        passengers = self.find_elements(*self.passengers_xpath)
        passengers[0].click()
        #passengers[1].click()
        #passengers[2].click()
        self.choosePassengerType()


        time.sleep(1)

    def submitOrder(self):
        self.smart_click(*self.submit_xpath)
        time.sleep(2)
        self.smart_click(*self.sure_xpath)
        time.sleep(10)